<?php
namespace app\index\validate;

use think\Validate;

class User extends Validate
{
    protected $rule = [
        'username' => 'require|min:1|unique:user',
        'password' => 'require|min:6',
        'repassword' => 'require|confirm:password',
        'idcard' => 'require|number|length:15,18',
        'email' => 'email|unique:user',
        'moblie' => '/^1[34578]\d{9}$/|unique:user',
        //'sex' => 'require|in:0,1',
        //'status' => 'require|in:0,1',
    ];

    protected $message = [
        'username.require' => '用户名必须填写',
        'username.min' => '用户名长度不能少于1位',
        //'username' => '{%username_val}',
        'username.unique' => '用户名已经存在，请重新填写',
        'password' => '密码不能为空',
        'password.min' => '密码长度不能少于6位',
        'repassword' => '确认密码不正确',
        'idcard.require' => '身份证号码不能为空',
        'idcard.number ' => '身份证号码必须为数字',
        'idcard.length' => '身份证号码必须为15到18位数字',
        'email' => '{%email_val}',
        'email.unique' => '{%email_unique}',
        'moblie' => '{%moblie_val}',
        'moblie.unique' => '{%moblie_unique}',
        //'sex' => '{%sex_val}',
        //'status' => '{%status_val}',
    ];

    protected $scene = [
        'add'   => ['username', 'password', 'repassword', 'moblie','idcard'],
        'edit'  => ['moblie','idcard'],
        'password' => ['password', 'repassword'],
        'status' => ['status'],
        'name' => ['name'],
    ];
}